/**
 * @return:$
 * @since: 1.0.0
 * @Author:WXX
 * @Date: 2020/9/8$ 16:56$
 */
/*
* 返回星期几
*
* */
function getWeekDay(date) {
  var weekDay = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
  // var myDate = new Date(Date.parse("2018/5/19"));
  var myDate = new Date(Date.parse(date));
  return weekDay[myDate.getDay()];
}
import moment from 'moment';
function timeEquation(time1,time2) {
  const date1=moment(time1,'hh:mm');
  const date2=moment(time2,'hh:mm');
  const date3=date2.diff(date1,'minute');//计算相差的分钟数
  const h=Math.floor(date3/60);//相差的小时数
  // const mm=date3%60;//计算相差小时后余下的分钟数
  return h;
}
function timeSecondEquation(time1,time2) {
  // time2比time1晚几个小时
  const date1=moment(time1,'hh:mm');
  const date2=moment(time2,'hh:mm');
  const date3=date2.diff(date1,'minute');//计算相差的分钟数
  // const h=Math.floor(date3/60);//相差的小时数
  const mm=date3%60;//计算相差小时后余下的分钟数
  return mm;
}

function weekTimeList() {
  let array = [];
  for(let i=0;i<24;i++){
    let name = i<10?`0${i}:00`:`${i}:00`
    let json = {
      id:i,
      name
    }
    array.push(json)
  }

  return array ;
}
// 返回弹窗位置
function checkPosition(x,y) {
  let json = {
    x,y
  }
  let screenH = window.screen.height;
  let screenW = window.screen.width;
  if(screenH-y<300){
    json.y -=250;
  }
  if(screenW-x<450){
    json.x -=400;
  }
  return json;
}
/**
 * 当天是第几周
* */
function getMonthWeek(y, m, c) {
  /*
y = d = 当前日期
m = 6 - w = 当前周的还有几天过完(不算今天)
y + b 的和在除以7 就是当天是当前月份的第几周
*/
  var date = new Date(y, parseInt(m) - 1, c),
    w = date.getDay(),
    d = date.getDate();
  return Math.ceil((d + 6 - w) / 7);
}
/**
  date1是当前日期
  date2是当年第一天
  d是当前日期是今年第多少天
  用d + 当前年的第一天的周差距的和在除以7就是本年第几周
  */
function getYearWeek(a, b, c) {
  var date1 = new Date(a, parseInt(b) - 1, c),
    date2 = new Date(a, 0, 1),
    d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
  return Math.ceil((d + ((date2.getDay() + 1) - 1)) / 7);
}

/**
* 判断是不是全天
* */
function isAllDay(begin,end){
  let beginDateTime = moment(begin).format('HH:mm');
  let endDateTime = moment(end).format('HH:mm');
  if(beginDateTime=='00:00'&&endDateTime=='00:00'){
    // 判断是不是全天
    return true;
  }else{
    return false;
  }
}

export {
  getWeekDay,
  timeEquation,
  timeSecondEquation,
  weekTimeList,
  checkPosition,
  getMonthWeek,
  getYearWeek,
  isAllDay,
}